package dao.impl;

import dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;
import utils.MyBatisUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserDaoimpl implements UserDao {
    public List<User> findAll() {
        //TODO
        //引入mybatis配置文件
        return MyBatisUtil.getSqlSession().getMapper(UserDao.class).findAll();



    }
    public int addUser(User user)
    {
       SqlSession session=MyBatisUtil.getSqlSession();
       int result=session.getMapper(UserDao.class).addUser(user);
       session.commit();
       return result;
    }

    @Override
    public User findById(Integer id) {
        return MyBatisUtil.getSqlSession().getMapper(UserDao.class).findById(id);
    }

    @Override
    public int UpdateUser(User user) {
        SqlSession session=MyBatisUtil.getSqlSession();
        int result=session.getMapper(UserDao.class).UpdateUser(user);
        session.commit();
        return result;
    }

    @Override
    public int DeleteUserById(Integer id) {
        SqlSession session=MyBatisUtil.getSqlSession();
        int result=session.getMapper(UserDao.class).DeleteUserById(id);
        session.commit();
        return result;
    }
}
